<template>
<div class="container">
  <div class="operation">
    <div class="title">
      <div style="font-size: 16px">
        {{label}}
      </div>
      <div v-if="pageType == 5" style="color: red; font-size: 12px; font-weight: 400; white-space: pre-wrap; word-wrap: break;">{{updateMsg}}</div>
    </div>
    <div>
      <template v-if="[2,3,6].indexOf(pageType) != -1">
        <el-button type="primary" @click="approvalPass">审核通过</el-button>
        <el-button type="danger" @click="approvalBackReasonVisible = true">审核驳回</el-button>
      </template>
      <template v-if="pageType == 4">
        <el-button type="primary" @click="approvalPass">审核通过</el-button>
      </template>
      <el-button type="primary" v-if="pageType==1 && showApprovalNew" @click="createApproval">提交新增审核</el-button>
      <el-button v-if="!disabled" type="primary" @click="handleSubmit">保存</el-button>
      <el-button @click="editBack">返回</el-button>
    </div>
  </div>
  <template v-if="pageType==6">
    <el-table :data="updateData" border style="width: 100%" stripe header-cell-class-name="table-head-cell" cell-class-name="table-cell-class" highlight-current-row>
      <template v-for="(item, index) of updateHeaders">
        <el-table-column v-if="item.prop=='operate'" fixed="right" align='center' label="操作">
          <template slot-scope="scope">
            <el-button @click="removeRelated(scope.row)" type="text" size="small"></el-button>
          </template>
        </el-table-column>
        <el-table-column fixed v-else align='center' :key="index" :prop="item.prop" :label="item.label">
        </el-table-column>
      </template>
    </el-table>
  </template>
  <el-form class="form" ref="form" :model="formData" label-width="140px" size="small" status-icon>
    <el-form-item :style="item.type == 'empty'?'visibility: hidden':''" class="form-item" v-for="(item, index) of conItems" :label="item.name" :key="index" :required="item.required">
      <el-input v-if="item.type == 'empty'" class="hidden"/>
      <!-- 单个输入 -->
      <el-input :disabled="disabled || item.disable" v-if="item.type == 'text'" v-model="formData[item.key]" :placeholder="item.placeholder"></el-input>
      <el-input type="textarea" style="width: 100%;" :disabled="disabled || item.disable" v-if="item.type=='textarea'" v-model="formData[item.key]" :placeholder="item.placeholder"></el-input>
      <!-- 一行多个输入 -->
      <el-row v-if="item.type=='multi-text'">
        <el-col :span="textItem.span" v-for="(textItem,index) of item.texts" :key="index">
          <el-input :disabled="disabled || item.disable || textItem.disable" :placeholder="textItem.placeholder" v-model="formData[textItem.key]">
            <template v-if="textItem.name" slot="append">{{textItem.name}}</template>
          </el-input>
        </el-col>
      </el-row>
      <!-- 搜索的输入框 -->
      <el-input v-if="item.type=='search'" :disabled="disabled || item.disable" readonly :placeholder="item.placeholder" v-model="formData[item.key]">
        <el-button v-if="!disabled && !item.disable" slot="append" icon="el-icon-search" @click="search(item)"></el-button>
      </el-input>
      <el-input type="textarea" :disabled="disabled || item.disable" v-if="item.type == 'textarea'" v-model="formData[item.key]" :placeholder="item.placeholder"></el-input>
      <!-- 带checkbox输入 -->
      <el-row v-if="item.type=='checktext'" type="flex" justify="space-between" style="width: 100%;">
        <el-col :span="11">
          <el-input :disabled="disabled || item.disable || formData[item.key + 'Checked']" v-model="formData[item.key]" :placeholder="item.placeholder"></el-input>
        </el-col>
        <el-col v-if="!disabled && !item.disable" :span="12">
          <el-checkbox :disabled="disabled || item.disable" v-model="formData[item.key + 'Checked']" :checked="formData[item.key + 'Checked']" :label="item.checkname" name="type"></el-checkbox>
        </el-col>
      </el-row>
      <!-- 单选 -->
      <el-select loading-text="加载中" :disabled="disabled || item.disable" class="single" v-if="item.type == 'single-select'" v-model="formData[item.key]" @change="((el)=>{selectChange(el,item.key)})" placeholder="请选择" @focus="getSelectOption(item)">
        <el-option v-for="(option, index) of item.options" :key="index" :label="option.name" :value="option.value"></el-option>
      </el-select>
      <!-- 一行多个选择 -->
      <div v-if="item.type=='multi-select'" style="display: flex; flex-direction:row; width: 100%;flex-wrap: wrap;">
        <template v-for="(options, index) of item.optionss">
          <div style="width: 115px;display: flex;">
            <el-select style="width: 85px;" loading-text="加载中" :disabled="disabled || item.disable || options.disable" class="single" v-model="formData[options.key]" @change="((el)=>{selectChange(el,options.key)})" placeholder="请选择" @focus="getSelectOption(options)">
              <el-option v-for="(option, index) of options.options" :key="index" :label="option.name" :value="option.value"></el-option>
            </el-select>
            <div style="width: 30px;">{{['省', '市', '区县'][index]}}</div>
          </div>
        </template>
      </div>
      <!-- checkbox -->
      <el-checkbox :disabled="disabled || item.disable" name="type" v-if="item.type=='checkbox'" v-model="formData[item.key]" :checked="formData[item.key] == 1 || formData[item.key] == true"></el-checkbox>
      <!-- 坐标 -->
      <template v-if="item.type=='location'">
        <el-row style="width: 100%">
          <el-col :span="1">
            X
          </el-col>
          <el-col :span="23">
            <el-input :disabled="disabled || item.disable" v-model="formData[item.key1]" placeholder=""></el-input>
          </el-col>
        </el-row>
        <el-row style="width: 100%">
          <el-col :span="1">
            Y
          </el-col>
          <el-col :span="23">
            <el-input :disabled="disabled || item.disable" v-model="formData[item.key2]" placeholder=""></el-input>
          </el-col>
        </el-row>
      </template>
      <!-- 特殊日期 -->
      <template v-if="item.type=='date'">
        <el-row>
          <el-col :span="8">
            <el-input style="" :disabled="disabled || item.disable" v-model="formData[item.year]" type="number"></el-input>
          </el-col>
          <el-col :span="1">
            年
          </el-col>
          <el-col :span="8">
            <el-select loading-text="加载中" :disabled="disabled || item.disable" class="single" v-model="formData[item.month]" placeholder="请选择" @focus="getSelectOption(item)" >
              <el-option v-for="(option, index) of item.options" :key="index" :label="option.name" :value="option.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="1">
            月
          </el-col>
        </el-row>
      </template>
    </el-form-item>
    <!-- 备注 -->
    <el-form-item v-if="!this.originalData && pageType == 1" style="width: 100%;" class="form-item" label="备注">
      <el-input type="textarea" v-model="formData.memo"></el-input>
    </el-form-item>
    <el-divider class="divider"></el-divider>
    <el-row v-if="pageType==1" style="font-size: 15px;font-weight: 500; margin-top: 10px">
      【门店名称】{{formData.retailName}}【门店地址】{{formData.province}}，{{formData.physicalCity}}，{{formData.adminCity}}，{{formData.deAddress}}
    </el-row>
    <el-row style="width: 100%; padding: 20px; padding-bottom: 0" justify="space-between" type="flex">
      <el-col :span="!disabled && this.tabItems[0].showPage?16:24">
        <el-radio-group v-model="tabIdx" size="small" @change="loadSubData">
          <el-radio-button v-for="(item, index) of tabItems" v-if="item.showPage" :key="index" :label="index">{{item.name}}</el-radio-button>
        </el-radio-group>
      </el-col>
      <el-col :span="8" v-if="!disabled && this.tabItems[0].showPage">
        <el-checkbox style="float: right;" v-model="formData['']" label=" 确认为新的门店，无需关联" name="type"></el-checkbox>
      </el-col>
    </el-row>
    <div style="padding: 5px; border: 1px solid #b0b0b0; width: 100%; display: flex; flex-wrap: wrap; flex-direction: row;">
      <template v-if="tabIdx==index" v-for="(tabItem, index) of tabItems">
        <div v-if="tabItem.type=='table' && tabItem.showPage" style="width: 100%; overflow-x: auto;">
          <template v-if="[5].indexOf(pageType) != -1 && index==1">
            <el-button style="margin-left: 20px; margin-top: 5px; margin-bottom: 10px;" size="mini" @click="createProvide">
              <img src="/static/img/16/add.png" style="vertical-align: text-bottom"/>
              新增
            </el-button>
            <el-button size="mini" @click="editProvide">
              <img src="/static/img/16/edit.png" style="vertical-align: text-bottom"/>
              编辑
            </el-button>
            <el-button size="mini" @click="provideSwitch">
              <img src="/static/img/16/2012080412111.png" style="vertical-align: text-bottom"/>
              供货关系开关
            </el-button>
          </template>
          <template v-if="(pageType == 1 || (pageType == 0 && disabled == false)) && index==1">
            <el-button style="margin-left: 20px; margin-top: 5px; margin-bottom: 10px;" size="mini" @click="createProvide">
              <img src="/static/img/16/add.png" style="vertical-align: text-bottom"/>
              新增
            </el-button>
            <el-button size="mini" @click="editProvide">
              <img src="/static/img/16/edit.png" style="vertical-align: text-bottom"/>
              编辑
            </el-button>
            <el-button size="mini" type="danger" @click="deleteProvide">
              <img src="/static/img/16/delete.png" style="vertical-align: text-bottom"/>
              删除
            </el-button>
          </template>
          <template v-if="pageType==4 && index==1">
            <el-button style="margin-left: 20px; margin-top: 5px; margin-bottom: 10px;" icon="el-icon-plus" size="mini" @click="coverSwitch">
              <img src="/static/img/16/key.png" style="vertical-align: text-bottom"/>
              SFA覆盖开关
            </el-button>
          </template>
           <template v-if="pageType==5 && index==7">
            <el-button style="margin-left: 20px; margin-top: 5px; margin-bottom: 10px;" size="mini" @click="editPosInfo">
              <img src="/static/img/16/edit.png" style="vertical-align: text-bottom"/>
              编辑
            </el-button>
          </template>
          <el-table show-header :data="tabItem.data" border style="width: 100%" stripe header-cell-class-name="table-head-cell" cell-class-name="table-cell-class" highlight-current-row @row-click="rowClick" @cell-click="cellClick">
            <template v-for="(header, index) of tabItem.headers">
              <el-table-column v-if="header.prop=='operate'" align='center' label="操作">
                <template slot-scope="scope">
                  <el-popconfirm v-for="(operate, index) of header.operates" :key="index" v-if="scope.row[operate.key] == 1 || !operate.key" confirmButtonText='确定' cancelButtonText='不用了' icon="el-icon-info" iconColor="red" :title="'确定要【' + operate.name +'】吗？'" @onConfirm="operate.action(scope.row)">
                    <el-button slot="reference" type="primary" plain size="small">{{operate.name}}</el-button>
                  </el-popconfirm>
                </template>
              </el-table-column>
              <template v-else>
                <el-table-column v-if="index == 1 && (pageType == 6 || pageType == 5 || pageType == -3) && tabIdx == 2" class-name="click-able" :align='header.align' :key="index" :prop="header.prop" :label="header.label"
                                :width="header.width?header.width:(getMaxLength(tabItem.data, header.prop) < (header.label.length * 13 + 20)?(header.label.length * 13 + 20):getMaxLength(tabItem.data, header.prop))">
                </el-table-column>
                <el-table-column v-else :align='header.align' :key="index" :label="header.label" :min-width="header.minWidth?header.minWidth:0"
                                :width="header.width?header.width:(getMaxLength(tabItem.data, header.prop) < (header.label.length * 13 + 20)?(header.label.length * 13 + 20):getMaxLength(tabItem.data, header.prop))">
                  <template slot-scope="scope">
                    <span v-if="typeof scope.row[header.prop] == 'number' && (scope.row[header.prop] == 0 || scope.row[header.prop] == 1) && ['radio', 'radio1', 'radio2'].indexOf(header.prop) == -1">{{ scope.row[header.prop] == 0 ? "否":"是" }}</span>
                    <span v-else>{{['radio1', 'radio2'].indexOf(header.prop) == -1?scope.row[header.prop]:(scope.row[header.prop].toFixed(2) + '%')}}</span>
                  </template>
                </el-table-column>
              </template>

            </template>
          </el-table>
        </div>
        <template v-if="tabItem.type=='text' && tabItem.showPage">
          <el-form-item v-for="(text, index) of tabItem.texts" :key="index + '_text'" class="form-item" :label="text.label">
            <el-input v-if="text.type=='text'" :disabled="text.disable" v-model="formData[text.key]" :placeholder="text.placeholder"></el-input>
            <el-input v-if="text.type=='search'" :disabled="text.disable" readonly v-model="formData[text.key]">
              <el-button v-if="!text.disable" slot="append" icon="el-icon-search" @click="search(text)"></el-button>
            </el-input>
          </el-form-item>
        </template>
      </template>
    </div>
  </el-form>
  <CommonSubEdit v-if="showEdit" :label="editTitle" :tips="editTips" :originalData="row" @getSelectOption="getSelectOption" @search="search" :items="editItems" @close="closeSubEdit" @submit="saveProvide"/>
  <CommonSubEdit v-if="showPosInfo" :label="editTitle" :tips="editTips" :originalData="row" @getSelectOption="getSelectOption" @search="search" :items="editPosInfoItems" @close="closePosEdit" @submit="savePosInfo"/>
  <CommonSubEdit v-if="showStore" label="查看原始门店信息" showAddress="showEditStoreAddress" :disabled="storeDisabled" :originalData="storeData" :tabItems="storeTabItems" :items="storeItems" @close="closeStore"/>
  <el-dialog title="驳回理由" :visible.sync="approvalBackReasonVisible" :modal-append-to-body='false'>
    <el-input type="textarea" autocomplete="off" v-model="approvalBackReason" placeholder="请输入驳回理由"/>
    <div slot="footer" class="dialog-footer">
      <el-button @click="approvalBackReasonVisible = false">取 消</el-button>
      <el-button type="primary" @click="approvalBack">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
import {setToken,getToken} from "@/util";
import Tools from "@/util/Tools.js";
import http from '@/api/http'
import {Message} from 'element-ui'
import CommonSubEdit from '../../common/CommonSubEdit'
export default {
  name: 'StoreEdit',
  components: {CommonSubEdit},
  data() {
    return {
      approvalBackReason: '',
      approvalBackReasonVisible: false,
      updateMsg: '',
      datePickerEdit: false,
      showEdit: false,
      showPosInfo: false,
      showStore: false,
      storeDisabled: true,
      storeData: {},
      showEditStoreAddress: true,
      editTips: '',
      editTitle: '',
      formData: this.originalData ? this.originalData : {},
      storeTabItems: [],
      conItems: this.items,
      storeItems: this.items,
      isAdministrator: 0,
      editItems:[
      {
          name: '供货方编码',
          key: 'soldToCode',
          type: 'search',
          disable: true,
          required: true
      },
      {
          name: '供货方名称',
          key: 'smmsName',
          type: 'text',
          disable: true,
          required: true
      },
      {
          name: 'BU - 业务单位',
          key: 'buName',
          vkey: 'fkBu',
          type: 'single-select',
          options:[],
          disable: true,
          required: false
      },
      {
          name: '供货方式',
          key: 'typeName',
          vkey: 'fkDealerType1',
          type: 'single-select',
          options:[],
          disable: true,
          required: false
      },
      {
          name: '供货方负责人',
          key: 'repName',
          type: 'text',
          disable: true,
          required: true
      },
      {
          name: 'JDESCode',
          key: 'jdesCode',
          type: 'text',
          disable: true,
          required: true
      },
      {
          name: '是否申请费用',
          key: 'isFee',
          type: 'checkbox',
          disable: false,
          required: false
      },
      {
          name: 'TPWF code',
          key: 'tpwfCode',
          type: 'text',
          disable: true,
          required: false
      },
      {
          name: 'SFA销售主管',
          key: 'sfaRepName',
          vkey: 'fkSfaRep',
          type: 'search',
          disable: false,
          required: false
      },
      {
          name: '是否SFA覆盖',
          key: 'isSfa',
          type: 'checkbox',
          disable: false,
          required: false
      },
      {
          name: 'SFA不覆盖原因',
          key: 'sfaReason',
          type: 'textarea',
          disable: false,
          required: false
      },
      {
          name: 'SFA门店编码',
          key: 'storesCode',
          type: 'text',
          disable: true,
          required: false
      }
      ],
      editPosInfoItems:[
      {
          name: '外部系统编码',
          key: 'code',
          type: 'text',
          disable: true,
          required: true
      },
      {
          name: 'Vendor',
          key: 'vendor',
          type: 'text',
          disable: false,
          required: true
      },
      {
          name: 'StoreCode',
          key: 'storeCode',
          type: 'text',
          disable: false,
          required: false
      },
      {
          name: 'POS门店类型',
          key: 'posRetailerType',
          type: 'text',
          disable: false,
          required: false
      },
      {
          name: '婴儿货架类型',
          key: 'shelfTypeA',
          type: 'text',
          disable: false,
          required: true
      },
      {
          name: '沐浴露货架类型',
          key: 'shelfTypeB',
          type: 'text',
          disable: false,
          required: true
      }
      ],
      tabIdx: 0,
      page: 1,
      pageSize: 15,
      tabItems: [],
      row: null,
      updateData: [],
      updateHeaders: [{
        prop: 'logTime',
        label: '变更日期'
      }, {
        prop: 'chineseName',
        label: '变更申请人'
      }, {
        prop: 'logInfo',
        label: '变更内容'
      }, {
        prop: 'retailerStatus',
        label: '变更审核状态'
      }, {
        prop: 'modifyTime',
        label: '变更审核时间'
      }],
    }
  },
  props: {
    showpp: Boolean,
    disabled: Boolean, // 是否不可编辑
    update: Boolean, // 是否是变更
    showApprovalNew: {
      type: Boolean,
      default() {
        return false
      }
    },
    originalData: {
      type: Object,
      default () {
        return null
      }
    },
    label: {
      type: String,
      default() {
        return ''
      }
    },
    pageType: {
      type: Number,
      default() {
        return -4
      }
    },
    items: {
      type: Array,
      default () {
        return []
      }
    },
  },
  methods: {
    selectChange(itemId, key) {
      for (let idx in this.conItems) {
        let item = this.conItems[idx]
        if (item.type == 'single-select' || item.type == 'multi-select') {
          if (item.key == 'city') {
            if (key == 'province') {
              this.formData.physicalCity = null
              this.formData.adminCity = null
              this.formData.fkCityType = null
              item.optionss[1].options = []
              item.optionss[2].options = []
            } else if (key == 'physicalCity') {
              item.optionss[2].options = []
              this.formData.adminCity = null
              this.formData.fkCityType = null
            }
          } else if (item.key == key) {
            this.formData[item.vkey] = itemId
          }
        } else {
          continue
        }
      }
      if (key == 'adminCity') {
        let item = this.$select
        if (item) {
          for (let idx in item.options) {
            let option = item.options[idx]
            if (option.adminCity == itemId) {
              let data = Object.assign({}, this.formData)
              data.fkAdminCity = option.fkAdminCity
              data.fkCityType = option.fkCityType
              data.cityTypeName = option.cityTypeName
              this.formData = data
              break;
            }
          }
        }
      } 
      else if (key == "retailType") {
        let item = this.$select
        if (item) {
          this.formData[item.vkey] = itemId
        }
      } 
      else if (key == "locationName") {
        let item = this.$select
        if (item) {
          this.formData[item.vkey] = itemId
        }
      } 
      else if (key == "isLKAvalue") {
        let item = this.$select
        if (item) {
          const optionArray=item.options;
          this.formData[item.vkey] = itemId
          for (let index = 0; index < optionArray.length; index++) {
            const option = optionArray[index];
            if(option.isLKA==itemId){
              this.formData[item.key] = item.options[index].isLKAvalue;
            }
          }
        }
      } 
    },
    /* 获取选择器选项，由宿主组件提供数据 */
    getSelectOption(item, data) {
      this.$select = item
      if (item.key == "retailType") {
        Tools.getStoreType(data=>{
          data.forEach(item => {
            item.name = item.retailName
            item.value = item.pkid
          })
          item.options = data
        })
      } else if (item.key == "locationName") {
        Tools.getLocationList(data=>{
          data.forEach(item => {
            item.name = item.locationName
            item.value = item.pkid
          })
          item.options = data
        })
      }else if (item.key == "isLKAvalue") {
        Tools.getisLkaList(data=>{
          data.forEach(item => {
            item.name = item.isLKAvalue
            item.value = item.isLKA
          })
          item.options = data
        })
      }else if (item.key == "levelName") {
        Tools.getStoreInvestType(data=>{
          data.forEach(item => {
            item.name = item.levelName
            item.value = item.pkid
          })
          item.options = data
        })
      } else if (item.key == "businessStatus") {
        Tools.getBussinessStatus(data=>{
          data.forEach(item => {
            item.name = item.dvalue
            item.value = item.dkey
          })
          item.options = data
        })
      } else if (item.key == "cooperationStatus") {
        Tools.getCooperationStatus(data=>{
          data.forEach(item => {
            item.name = item.dvalue
            item.value = item.dkey
          })
          item.options = data
        })
      } else if (item.key == "province") {
        Tools.getProvince(data => {
          data.forEach(item => {
            item.name = item.provinceName
            item.value = item.provinceName
          })
          item.options = data
        })
      } else if (item.key == "physicalCity") {
        Tools.getCity({provinceName: this.formData.province},data => {
          data.forEach(item => {
            item.name = item.cityName
            item.value = item.cityName
          })
          item.options = data
        })
      } else if (item.key == "adminCity") {
        Tools.getAdminCity({provinceName: this.formData.province, cityName: this.formData.physicalCity},data => {
          data.forEach(item => {
            item.name = item.adminCity
            item.value = item.adminCity
            item.fkAdminCity = item.pkid
            item.fkCityType = item.fkCityType
          })
          item.options = data
        })
      } else if (item.key == 'businessTime') {
        let options = []
        for (let i=0; i< 13; i++) {
          options.push({
            name: i==0?'请选择':('' + i),
            value: '' + i
          })
        }
        item.options = options
      }
    },
    cellClick(row, column) {
      if((this.pageType == 6 || this.pageType == 5 || this.pageType == -3) && this.tabIdx == 2 && column.property == 'code') {
        this.storeData = row
        this.showStore = true
      }
    },
    rowClick(row) {
      this.row = row
    },
    handleSubmit(e) {
      // 保存
      this.$emit('submit', this.formData)
    },
    search(item, callback) {
      if (typeof callback == 'function') {
        this.$emit('search', item, callback)
      } else {
        this.$emit('search', item, (obj) => {
          // 已绑定的对象不允许动态添加属性，添加了也不会生成setter和getter
          let data = Object.assign({}, this.formData)
          this.formData = Object.assign(data, obj)
        })
      }
    },
    editBack() {
      this.$emit('editBack')
    },
    removeRelated(item) {
      // 审批单移除关联

    },
    handleSizeChange(size) {
      this.pageSize = size
      this.loadSubData(this.tabIdx)
    },
    handleCurrentChange(page) {
      this.page = page
      this.loadSubData(this.tabIdx)
    },
    loadSubData(index) {
      if (this.formData) {
        this.row = null
        if (!this.tabItems[index].url) { return }
        let params = {pageNum: this.page, pageSize: this.pageSize,}
        params = Object.assign(params, this.formData)
        http.get(this.tabItems[index].url, params).then(resp => {
          if (resp instanceof Array) {
            this.tabItems[index].data = resp
          } else {
            this.tabItems[index].data = resp.list
          }
        }, msg => {})
      }
    },
    closeSubEdit() {
      this.showEdit = false
      this.loadSubData(this.tabIdx)
    },
    closePosEdit() {
      this.showPosInfo = false
      this.loadSubData(this.tabIdx)
    },
    createProvide() {
      this.editTitle = '供货经销商 - 添加'
      this.editTips = '*注：门店类型为Hyper/Normal Super/Premium Super, 当SFA不覆盖时需要录【SFA不覆盖原因】'
      this.showEdit = true
      this.editItems[0].disable = false
      this.editItems[5].disable = false
      this.editItems[7].disable = false
      this.editItems[11].disable = false
      this.row = null;
    },
    editProvide() {
      if (!this.row) {
        Message({type: 'error', message: '请选择一条数据'})
        return;
      }
      this.editTitle = '供货经销商 - 编辑'
      this.editTips = '*注：门店类型为Hyper/Normal Super/Premium Super, 当SFA不覆盖时需要录【SFA不覆盖原因】'
      this.showEdit = true
      this.editItems[0].disable = true
      if(this.isAdministrator>0){
          this.editItems[5].disable = false,
          this.editItems[7].disable = false,
          this.editItems[11].disable = false,
          this.editItems[6].disable = false,
          this.editItems[9].disable = false
      }

    },
    saveProvide(formData) {
      formData.guid = this.formData.guid
      if (this.formData.pkid) {
        formData.fkRetailer = this.formData.pkid
      }
      if (this.row) {
        http.post(this.$api.API_STORE_RETAILER_UPDATE,formData)
            .then(resp=>{
              this.showEdit = false
              this.row = null
              Message({type: 'success', message: '供应商编辑-保存成功'})
              this.loadSubData(this.tabIdx)
            })
        return;
      }
      http.post(this.$api.API_STORE_RETAILER_SAVE,formData)
          .then(resp=>{
            this.showEdit = false
            this.row = null
            Message({type: 'success', message: '供应商新增-保存成功'})
            this.loadSubData(this.tabIdx)
          })
    },
    deleteProvide() {
      if (!this.row) {
        Message({type: 'error', message: '请选择一条数据'})
        return;
      }
      this.$confirm('您确认要删除供货方 “' + this.row.smmsName + '” 吗？', '提示', {
        confirmButtonText: '确认删除',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        http.post(this.$api.API_STORE_RETAILER_DELETE, {pkid: this.row.pkid})
            .then(resp=>{
              Message({type: 'success', message: '门店已删除！'})
              this.loadSubData(this.tabIdx)
            })
      }).catch(() => {});
    },
    provideSwitch() {
      if (!this.row) {
        Message({type: 'error', message: '请选择一条数据'})
        return;
      }
      if (this.formData.retailerDealerIds && this.formData.retailerDealerIds.length > 0 && this.row.pkid == this.formData.retailerDealerIds[0]) {
        Message({type: 'warning', message:'请勿重复操作，请点击【保存】按钮'})
        return
      }
      this.formData.retailerDealerIds = [this.row.pkid]
      http.post(this.$api.API_RETAILER_DEALER_ISSUPPLY, {pkid: this.row.pkid,isSupply: this.row.supply,fkRetailer: this.row.fkRetailer})
          .then(resp=>{
            this.loadSubData(this.tabIdx)
          })
      Message({type: 'success', message:'供货关系变更成功，请点击【保存】按钮'})
    },
    coverSwitch() {
      if (!this.row) {
        Message({type: 'error', message: '请选择一条数据'})
        return;
      }
      http.post(this.$api.API_STORE_SFA_RECOVER_SWITCH, {pkid: this.row.pkid})
          .then(resp=>{
            this.loadSubData(this.tabIdx)
          })
    },
    editPosInfo() {
      if (!this.row) {
        Message({type: 'error', message: '请选择一条数据'})
        return;
      }
      this.editTitle = 'POS信息 - 编辑'
      this.showPosInfo = true
      this.editPosInfoItems[0].disable = true
    },
    savePosInfo(formData) {
      if (this.row) {
        http.post(this.$api.API_POSINFO_UPDATE,formData)
          .then(resp=>{
            this.showPosInfo = false
            this.row = null
            Message({type: 'success', message: 'POS信息编辑-保存成功'})
            this.loadSubData(this.tabIdx)
          })
        return;
      }
    },
    approvalPass() {
      this.$emit('approvalPass', this.formData)
    },
    approvalBack() {
      this.approvalBackReasonVisible = false
      this.$emit('approvalBack', this.formData,this.approvalBackReason)
    },
    closeStore() {
      this.showStore = false
      this.storeData = {}
    },
    updateChange() {
      let indexs = []
      for (let idx in this.conItems) {
        let key = this.conItems[idx].key
        if (key == 'businessTime') {
          let year = this.conItems[idx].year
          let month = this.conItems[idx].month
          if (!this.conItems[idx].disable && (this.formData[year] != this.originalData[year] || this.formData[month] != this.originalData[month])) {
            indexs.push(idx)
          }
        } else if (key == 'city') {
          for (let item of this.conItems[idx].optionss) {
            if (this.formData[item.key] != this.originalData[item.key]) {
              indexs.push(idx)
              break
            }
          }
        } else {
          if (!this.conItems[idx].disable && this.formData[key] != this.originalData[key]) {
            indexs.push(idx)
          }
        }
      }
      if (indexs.length > 0) {
        this.updateMsg = '变更内容:'
        for (let index of indexs) {
          let item = this.conItems[index]
          if (item.key == 'businessTime') {
            let oldValue = !this.originalData[item.year] && !this.originalData[item.month]?'null':(this.originalData[item.year]?(this.originalData[item.year] + '年'):'') + (this.originalData[item.month]?(this.originalData[item.month] + '月'):'')
            let newValue = !this.formData[item.year] && !this.formData[item.month]?'null':(this.formData[item.year]?(this.formData[item.year] + '年'):'') + (this.formData[item.month]?(this.formData[item.month] + '月'):'')
            this.updateMsg += '\n       ' + item.name + '的值由：《' + oldValue + '》变更为：《' + newValue + '》'
          } else if (item.key == 'city') {
            let oldValue = ''
            let newValue = ''
            for (let idx in item.optionss) {
              let subItem = item.optionss[idx]
              oldValue += idx == 0?'':',' + this.originalData[subItem.key]?this.originalData[subItem.key]:''
              newValue += idx == 0?'':',' + this.formData[subItem.key]?this.formData[subItem.key]:''
            }
            this.updateMsg += '\n       ' + item.name + '的值由：《' + oldValue + '》变更为：《' + newValue + '》'
          } else {
            this.updateMsg += '\n       ' + item.name + '的值由：《' + this.originalData[item.key] + '》变更为：《' + this.formData[item.key] + '》'
          }

        }
      } else {
        this.updateMsg = ''
      }
    },
    createApproval() {
      this.$emit('createApproval', this.formData)
    },
    getMaxLength (arr, key) {
    return arr.reduce((acc, item) => {
      if (item[key]) {
        const str = item[key].toString()
        const upLetter = str.match(/[A-Z]/g)
        const upLetterLen = upLetter ? upLetter.length : 0
        const lowLetter = str.match(/[a-z]/g)
        const lowLetterLen = lowLetter ? lowLetter.length : 0
        const char = str.match(/[\u2E80-\u9FFF]/g)
        const charLen = char ? char.length - upLetterLen - lowLetterLen : 0
        const num = str.match(/\d|\./g)
        const numLen = num ? num.length : 0
        const otherLen = str.length - upLetterLen - lowLetterLen - charLen - numLen
        let calcLen = charLen * 1.0 + upLetterLen * 0.65 + numLen * 0.55 + lowLetterLen * 0.48 + otherLen * 0.8
        if (acc < calcLen) {
          acc = calcLen
        }
      }
      return acc
    }, 0) * 13 + 20
  },
  isadminitrator(){
     this.$http.post(this.$api.API_QUERYMDM_ISADMINITRATOR).then(resp=>{
      this.isAdministrator=resp
     })
  },
  },
  watch: {
    tabIdx(newIdx, oldIdx) {
      if (newIdx != oldIdx) {
        this.row = null
      }
    },
    formData: {
      deep: true,
      handler(newValue, oldValue) {
        if (this.pageType == 5 && this.originalData) { // 门店变更
          this.updateChange()
        }
      }
    }
  },
  created() {
    this.isadminitrator(),
    this.storeTabItems = [
      {
        name: '供货方',
        showPage: true,
        type: 'table',
        url: this.$api.API_STORE_RETAILER_LIST,
        data: [],
        headers:[{
          prop: 'soldToCode',
          label: '供货方编码'
        },{
          prop: 'smmsName',
          label: '供货方名称'
        },{
          prop: 'buName',
          label: '业务单位'
        },{
          prop: 'supply',
          label: '供货关系状态'
        },{
          prop: 'typeName',
          label: '供货方式'
        },{
          prop: 'repName',
          label: '客户负责人'
        },{
          prop: 'isFee',
          label: '是否申请费用'
        },{
          prop: 'tpwfCode',
          label: 'TPWFcode'
        },{
          prop: 'jdesCode',
          label: 'JDEScode'
        },{
          prop: 'isSfa',
          label: '是否SFA覆盖'
        },{
          prop: 'sfaReason',
          label: 'SFA不覆盖原因'
        },{
          prop: 'sfaRepName',
          label: 'SFA销售主管'
        },{
          prop: 'storesCode',
          label: 'SFA门店编码'
        },{
          prop: 'changeStatus',
          label: '变更审核状态'
        }]
      },
      {
        name: 'SAP基础数据',
        showPage: true,
        type: 'text',
        texts: [{
          label: '付款用Vendor',
          type: 'search',
          key: 'vendorCode',
          disable: true,
        },{
          label: 'DistributionChannel',
          type: 'text',
          key: 'distributionChannel',
          disable: true,
        },{
          label: 'PayLink编码',
          type: 'search',
          key: 'payLinkCode',
          disable: true,
        },{
          label: 'PayLink名称',
          type: 'text',
          key: 'payLinkName',
          disable: true,
        }]
      }, {
        name: 'ShipTo信息',
        showPage: true,
        type: 'table',
        url: this.$api.API_SMMS_SHIPTO_LIST,
        headers: [{
          prop: 'shipToCode',
          label: 'ShipTo代码'
        }, {
          prop: 'shipToName',
          label: 'SoldTo名称'
        }, {
          prop: 'shipToAddress',
          label: 'SoldTo地址'
        }, {
          prop: 'memo',
          label: '备注'
        }, {
          prop: 'isValid',
          label: '是否有效'
        }, {
          prop: 'fkCreateUser',
          label: '创建人'
        }, {
          prop: 'createTime',
          label: '创建时间'
        }],
        data: []
      },{
        name: 'Payer信息',
        type: 'table',
        showPage: true,
        url:this.$api.API_SMMS_PLAYER_LIST,
        data: [],
        headers: [{
          prop: 'payerCode',
          label: 'Payer代码'
        }, {
          prop: 'payerName',
          label: 'Payer名称'
        }, {
          prop: 'payerAddress',
          label: 'Payer地址'
        }, {
          prop: 'memo',
          label: '备注'
        }, {
          prop: 'isValid',
          label: '是否有效'
        }, {
          prop: 'createUserName',
          label: '创建人'
        }, {
          prop: 'createTime',
          label: '创建时间'
        }]
      }, {
        name: 'POS信息',
        type: 'table',
        showPage: true,
        url:this.$api.API_GET_POSINFO,
        data: [],
        headers: [{
          prop: 'code',
          label: '外部系统编码',
          type: 'text',
          key: 'code',
          disable: true,
        },{
          label: 'Vendor',
          type: 'text',
          key: 'vendor',
          disable: true,
        },{
          label: 'StoreCode',
          type: 'text',
          key: 'storeCode',
          disable: true,
        },{
          label: 'POS门店类型',
          type: 'text',
          key: 'posRetailerType',
          disable: true,
        },{
          label: '婴儿货架类型',
          type: 'text',
          key: 'shelfTypeA',
          disable: true,
        },{
          label: '沐浴露货架类型',
          type: 'text',
          key: 'shelfTypeB',
          disable: true,
        }]
      }
    ]
    if (this.originalData) {
      this.formData.province = this.formData.province == "0" || this.formData.province == 0 ? "":this.formData.province
      this.formData.physicalCity = this.formData.physicalCity == "0" || this.formData.physicalCity == 0 ? "":this.formData.physicalCity
      this.formData.adminCity = this.formData.adminCity == "0" || this.formData.adminCity == 0 ? "":this.formData.adminCity
    } else {
      let data = {}
      for (let idx in this.conItems) {
        let item = this.conItems[idx]
        if (item.type == 'multi-select') {
          item.optionss.forEach(item=>{
            data[item.key] = null
          })
        } else if (item.type == 'multi-text') {
          item.texts.forEach(item=>{
            data[item.key] = null
          })
        } else {
          data[item.key] = null
        }
      }
      this.formData = data
    }

    if (this.formData.businessYear && this.formData.businessMonth) {
      this.formData.businessTime = this.formData.businessYear + ' 年 ' + this.formData.businessMonth + ' 月'
    } else if (this.formData.businessMonth) {
      this.formData.businessTime = this.formData.businessMonth + '月'
    } else if (this.formData.businessYear) {
      this.formData.businessTime = this.formData.businessYear + '年'
    }
    let self = this
    this.tabItems = [{
      name: '匹配结果',
      showPage: true,
      type: 'table',
      url: this.$api.API_STORE_MATCH_LIST,
      headers: [
      {
        prop: 'mdmCode',
        label: '统一编码'
      },
      {
        prop: 'code',
        label: '外部系统编码'
      },{
        prop: 'retailName',
        label: '门店全称'
      },{
        prop: 'retailerAddress',
        label: '门店详细地址'
      },{
        prop: 'retailGroup',
        label: '客户集团'
      },{
        prop: 'retailType',
        label: '门店类型'
      },{
        prop: 'relationStatus',
        label: '关联状态'
      },{
        prop: 'radio1',
        label: '门店名称匹配度'
      },{
        prop: 'radio2',
        label: '地址匹配度'
      },{
        prop: 'radio',
        label: '相似度得分'
      }],
      data: []
    },{
      name: '供货方',
      showPage: true,
      type: 'table',
      url: this.$api.API_STORE_RETAILER_LIST,
      data: [],
      headers:[{
        prop: 'soldToCode',
        label: '供货方编码'
      },{
        prop: 'smmsName',
        label: '供货方名称'
      },{
        prop: 'buName',
        label: '业务单位'
      },{
        prop: 'supply',
        label: '供货关系状态'
      },{
        prop: 'typeName',
        label: '供货方式'
      },{
        prop: 'repName',
        label: '客户负责人'
      },{
        prop: 'isFee',
        label: '是否申请费用'
      },{
        prop: 'tpwfCode',
        label: 'TPWFcode'
      },{
        prop: 'jdesCode',
        label: 'JDEScode'
      },{
        prop: 'isSfa',
        label: '是否SFA覆盖'
      },{
        prop: 'sfaReason',
        label: 'SFA不覆盖原因'
      },{
        prop: 'sfaRepName',
        label: 'SFA销售主管'
      },{
        prop: 'storesCode',
        label: 'SFA门店编码'
      },{
        prop: 'logStatus',
        label: '变更审核状态'
      }]
    },{
      name: '原始门店查看',
      showPage: true,
      type: 'table',
      url: this.$api.API_STORE_ORIGINAL_LIST,
      headers:[{
        prop: 'dataSource',
        label: '数据来源'
      },
      {
        prop: 'code',
        label: '外部系统编码'
      },
      {
        prop: 'jdesCode2',
        label: 'JDESCode'
      },{
        prop: 'cdccCode',
        label: 'CDCCCode'
      },{
        prop: 'retailName',
        label: '门店名称'
      },{
        prop: 'retailType',
        label: '门店类型'
      },{
        prop: 'retailGroup',
        label: '客户集团'
      },{
        prop: 'deAddress',
        label: '详细地址'
      },{
        prop: 'operate',
        label: '操作',
        operates:[{
          name: '移除关联',
          key: 'isRelated',
          action(item) {
            http.post(self.$api.API_STORE_ORIGINAL_RELATED_REMOVE, {originalPkid: item.pkid, pkid: self.formData.pkid})
                .then(resp=>{
                  Message({type: 'success', message: '移除关联成功！'})
                  self.loadSubData(self.tabIdx)
                })
          },
        },{
          name: '移除设定',
          key: 'isSettings',
          action(item) {
            http.post(self.$api.API_STORE_ORIGINAL_SETTING_REMOVE, {originalPkid: item.pkid, pkid: self.formData.pkid})
                .then(resp=>{
                  Message({type: 'success', message: '移除设定成功！'})
                  self.loadSubData(self.tabIdx)
                })
          },
        }]
      }],
      data: []
    },{
      name: '销售架构信息',
      showPage: true,
      type: 'table',
      url:this.$api.API_STORE_SALE_ARCHITECTURE_LIST,
      headers: [{
        prop: 'buName',
        label: '业务单位',
        align: 'center'
      },{
        prop: 'soldToCode',
        label: '供货方编码',
        align: 'center'
      },{
        prop: 'smmsName',
        label: '供货方名称',
        align: 'center'
      },{
        prop: 'regionName',
        label: '供货方Region',
        align: 'center'
      },{
        prop: 'areaName',
        label: '供货方Area',
        align: 'center'
      },{
        prop: 'retailerRegionName',
        label: '门店地理Region',
        align: 'center'
      },{
        prop: 'retailerAreaName',
        label: '门店地理Area',
        align: 'center'
      }],
      data: []
    },{
      name: 'SAP基础信息',
      showPage: true,
      type: 'text',
      texts: [{
        label: '付款用Vendor',
        type: 'search',
        key: 'vendorCode',
        disable: true,
      },{
        label: 'DistributionChannel',
        type: 'text',
        key: 'distributionChannel',
        disable: true,
      },{
        label: 'PayLink编码',
        type: 'search',
        key: 'payLinkCode',
        disable: true,
      },{
        label: 'PayLink名称',
        type: 'text',
        key: 'payLinkName',
        disable: true,
      }]
    }, {
      name: 'ShipTo信息',
      showPage: true,
      type: 'table',
      url: this.$api.API_STORE_SHIPTO_LIST,
      headers: [{
        prop: 'shipToCode',
        label: 'ShipTo代码',
        align: 'center'
      }, {
        prop: 'shipToName',
        label: 'SoldTo名称',
        align: 'center'
      }, {
        prop: 'shipToAddress',
        label: 'SoldTo地址',
        align: 'center'
      }, {
        prop: 'memo',
        label: '备注',
        align: 'center'
      }, {
        prop: 'isValid',
        label: '是否有效',
        align: 'center'
      }, {
        prop: 'fkCreateUser',
        label: '创建人',
        align: 'center'
      }, {
        prop: 'createTime',
        label: '创建时间',
        align: 'center'
      }],
      data: []
    },{
      name: 'Payer信息',
      type: 'table',
      showPage: true,
      url:this.$api.API_STORE_PAYER_LIST,
      data: [],
      headers: [{
        prop: 'payerCode',
        label: 'Payer代码',
        align: 'center'
      }, {
        prop: 'payerName',
        label: 'Payer名称',
        align: 'center'
      }, {
        prop: 'payerAddress',
        label: 'Payer地址',
        align: 'center'
      }, {
        prop: 'memo',
        label: '备注',
        align: 'center'
      }, {
        prop: 'isValid',
        label: '是否有效',
        align: 'center'
      }, {
        prop: 'createUserName',
        label: '创建人',
        align: 'center'
      }, {
        prop: 'createTime',
        label: '创建时间',
        align: 'center'
      }]
    },
    // {
    //   name: 'POS信息',
    //   type: 'table',
    //   showPage: true,
    //   type: 'text',
    //   texts: [{
    //     label: 'Vendor',
    //     type: 'text',
    //     key: 'vendor',
    //     disable: true,
    //   },{
    //     label: 'StoreCode',
    //     type: 'text',
    //     key: 'storeCode',
    //     disable: true,
    //   },{
    //     label: 'POS门店类型',
    //     type: 'text',
    //     key: 'posRetailerType',
    //     disable: true,
    //   },{
    //     label: '婴儿货架类型',
    //     type: 'text',
    //     key: 'shelfTypeA',
    //     disable: true,
    //   },{
    //     label: '沐浴露货架类型',
    //     type: 'text',
    //     key: 'shelfTypeB',
    //     disable: true,
    //   }]
    // },
    {
      name: 'POS信息',
      type: 'table',
      showPage: true,
      url:this.$api.API_GET_POSINFO,
      data: [],
      headers: [{
        prop: 'code',
        label: '外部系统编码',
        type: 'text',
        key: 'code',
        disable: true,
      },{
        prop: 'vendor',
        label: 'Vendor',
        type: 'text',
        key: 'vendor',
        disable: true,
      },{
        prop: 'storeCode',
        label: 'StoreCode',
        type: 'text',
        key: 'storeCode',
        disable: true,
      },{
        prop: 'posRetailerType',
        label: 'POS门店类型',
        type: 'text',
        key: 'posRetailerType',
        disable: true,
      },{
        prop: 'shelfTypeA',
        label: '婴儿货架类型',
        type: 'text',
        key: 'shelfTypeA',
        disable: true,
      },{
        prop: 'shelfTypeB',
        label: '沐浴露货架类型',
        type: 'text',
        key: 'shelfTypeB',
        disable: true,
      }]
    },
    {
      name: '变更日志',
      type: 'table',
      showPage: true,
      url: this.$api.API_STORE_UPDATE_LOG_LIST,
      data: [],
      headers: [{
        prop: 'logTime',
        label: '变更提交时间',
        align: 'center',
        width: '170'
      }, {
        prop: 'chineseName',
        label: '变更人',
        align: 'center',
        width: '100'
      }, {
        prop: 'retailerStatus',
        label: '变更状态',
        align: 'center',
        width: '100',
      }, {
        prop: 'modifyTime',
        label: '变更确认时间',
        align: 'center',
        width: '170',
      }, {
        prop: 'logInfo',
        label: '变更描述',
        align: 'left',
      }]
    }]
    switch (this.pageType) {
      case -3: {
        this.tabItems[0].showPage = false
        break;
      }
      case -2: {
        this.tabItems[0].showPage = false
        this.tabItems[2].showPage = false
        this.tabItems[3].showPage = false
        this.tabItems[8].showPage = false
        break;
      }
      case -1: {
        this.tabItems[0].showPage = false
        break;
      }
      case 0: {
        // SAP基础信息
        this.tabItems[0].showPage = false
        this.tabItems[2].showPage = false
        this.tabItems[3].showPage = false
        this.tabItems[8].showPage = false
        this.tabItems[4].texts[0].disable = true
        if (this.originalData) {
          this.tabItems[4].texts[2].disable = true
        } else {
          this.tabItems[4].texts[2].disable = false
        }
        // 移除变更审核状态列
        this.tabItems[1].headers.pop()
        break;
      }
      case 5: {
        this.tabItems[0].showPage = false
        this.tabItems[4].texts[2].disable = false
        this.tabItems[4].texts[0].disable = false
        break;
      }
      case 1: {
        // 任务 - 待处理门店
        this.tabItems[2].showPage = false
        this.tabItems[3].showPage = false
        this.tabItems[8].showPage = false
        let header = this.tabItems[1].headers[this.tabItems[1].headers.length-1]
        // header.prop = 'storesCode'
        // header.label = 'SFA门店编码'
        this.tabItems[0].headers.splice(6,1)
        this.tabItems[0].headers.push({
          prop: 'operate',
          label: '操作',
          operates: [{
            name: '关联',
            action: function(item) {
              // 匹配结果关联
              http.post(self.$api.API_STORE_MATCHRESILT_RELATED, {fkRetailer: item.pkid, pkid: self.formData.pkid})
                  .then(resp=>{
                    Message({type: 'success', message: '关联成功！'})
                    self.loadSubData(self.tabIdx)
                  })
            }
          }]
        })
        break;
      }
      case 2: {
        this.tabItems[2].showPage = false
        this.tabItems[3].showPage = false
        this.tabItems[8].showPage = false
        break;
      }
      case 3: {
        this.tabItems[2].showPage = false
        this.tabItems[3].showPage = false
        this.tabItems[8].showPage = false
        break;
      }
      case 6: {
        this.tabItems[0].showPage = false
        break;
      }
      case 4: {
        this.tabItems[0].showPage = false
        this.tabItems[3].showPage = false

        // 移除变更审核状态列
        this.tabItems[1].headers.pop()
        break;
      }
      default:{

      }
    }
    // 初始选中
    for (let idx in this.tabItems) {
      let tabItem = this.tabItems[idx]
      if (tabItem.showPage == true) {
        this.tabIdx = idx
        break;
      }
    }
    if (this.formData.fkVendor) {
      Tools.getVendor({fkVendor: this.formData.fkVendor}, resp=>{
        let data = Object.assign({}, this.formData)
        data.vendorCode = resp.vendorCode
        data.fkVendor = resp.pkid
        this.formData = data
      })
    }
    if (this.formData.fkPayLink) {
      Tools.getPaylink({fkPayLink: this.formData.fkPayLink}, resp=>{
        let data = Object.assign({}, this.formData)
        data.payLinkName = resp.payLinkName
        data.payLinkCode = resp.payLinkCode
        data.fkPayLink = resp.pkid
        this.formData = data
      })
    }
    if (this.formData.fkAdminCity) {
      Tools.getAdminCityInfo({fkAdminCity: this.formData.fkAdminCity}, resp=>{
        let data = Object.assign({}, this.formData)
        data.cityTypeName = resp.cityTypeName
        data.fkCityType = resp.fkCityType
        data.adminCity = resp.adminCity
        this.formData = data
      })
    }
    // 设置默认显示
    Tools.getBussinessStatus(data=>{
      if (!this.formData.businessStatus) {
        // this.formData.businessStatus = data[0].dkey
        this.formData.businessStatus = ''
        this.formData = Object.assign({}, this.formData)
      } else {
        let items = data.filter(item => item.dkey == this.formData.businessStatus)
        if (items.length <= 0) {
          this.formData.businessStatus = data[0].dkey
          this.formData = Object.assign({}, this.formData)
        }
      }
    })
    Tools.getCooperationStatus(data=>{
      if (!this.formData.cooperationStatus) {
        this.formData.cooperationStatus = ''
        this.formData = Object.assign({}, this.formData)
      } else {
        let items = data.filter(item => item.dkey == this.formData.cooperationStatus)
        if (items.length <= 0) {
          this.formData.cooperationStatus = data[0].dkey
          this.formData = Object.assign({}, this.formData)
        }
      }
    })
    Tools.getBuList(data=>{
      let items = data.filter(item => item.buName == this.formData.buName)
      if (items.length <= 0) {
        this.formData.buName = null
        this.formData.fkBu = null
      }
    })
    if (this.pageType==6) {
      http.get(this.$api.API_STORE_UPDATE_TASK_LOG_LIST,{pkid:this.formData.pkid})
          .then(resp=>{
            this.updateData = resp
          })
    }
    if (this.pageType >= 0) {
      http.get(this.$api.API_STORE_INFO,{pageType: this.pageType, pkid: this.formData.pkid})
          .then(resp=> {
            resp.retailerInfo.guid = resp.guid
            this.formData.fkDestination = resp.retailerInfo.fkDestination
            this.loadSubData(this.tabIdx)
            Tools.getDestinations(data=>{
              let items = data.filter(item => item.pkid == this.formData.fkDestination)
                if (items.length > 0) {
                  self.formData.destinationName = items[0].destinationName
                  self.formData = Object.assign({}, self.formData)
                } else {
                  self.formData.destinationName = data[0].destinationName
                  self.formData = Object.assign({}, self.formData)
                }
            })
          })
    } else {
      Tools.getDestinations(data=>{
        let items = data.filter(item => item.pkid == this.formData.fkDestination1)
          if (items.length > 0) {
            self.formData.destinationName = items[0].destinationName
            self.formData = Object.assign({}, self.formData)
          } else {
            self.formData.destinationName = data[0].destinationName
            self.formData = Object.assign({}, self.formData)
          }
      })
    }
    this.loadSubData(this.tabIdx)
  },
  mounted () {
    if (window.history && window.history.pushState) {
      history.pushState(null, null, document.URL)
      window.addEventListener('popstate', this.editBack, false)
    }
  },
  destroyed () {
    window.removeEventListener('popstate', this.editBack, false)
  },
}
</script>

<style lang="less" scoped>
.container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100%;
    background: white;
    z-index: 99;
    padding-bottom: 50px;
}
.title {
    font-size: 16px;
    font-weight: 600;
    color: #666666;
}
.operation {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    padding: 15px;
}
.form {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    border: 1px solid #f2f2f2;
    padding: 5px 0;
}
.form-item {
    width: calc(50% - 10px);
    margin: 5px 5px;
}
/deep/.el-form-item__label {
    font-size: 12px;
    text-align: center;
}
/deep/.el-select.single {
    width: 100%;
}
.hidden {
  visibility: hidden;
}
.table-head-cell {
  padding: 5px 0 !important;
  color: #000000 !important;
  font-size: 12px !important;
}
.table-cell-class {
  padding: 5px 0 !important;
  color: #000000;
  font-weight: 400;
  font-size: 12px !important;
}
.el-table th.is-hidden>* {
  visibility: visible! important;
}

/deep/tbody .click-able {
  color: blue;
  font-weight: bold;
  cursor: pointer;
}

.el-table .cell {
  white-space: pre-line;
}
.el-table {
  overflow: visible;
}
.divider {
  margin: 0;
}
/deep/.el-input.is-disabled .el-input__inner {
  cursor: text! important;
}
/deep/.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
  margin-bottom: 0! important;
}

/deep/.el-form-item--small .el-form-item__label {
  height: 100%;
  padding: 0;
  margin-right: 5px;
  background: #f1f1f1;
  border: 1px solid #e7e7e7;
  display: flex;
  align-items: center;
  justify-content: center;
}
/deep/.el-form-item--small .el-form-item__content {
  padding: 10px 10px;
  border: 1px solid #e7e7e7;
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 100%;
  flex-wrap: wrap;
}
/deep/.el-radio-button {
  margin-left: 5px;
}
/deep/.el-radio-button:first-child {
  margin-left: 0;
}
/deep/.el-radio-button:first-child .el-radio-button__inner {
  border-radius: 0;
}

/deep/.el-radio-button:last-child .el-radio-button__inner {
  border-radius: 0;
}

/deep/.el-radio-button__inner {
  border-left: 1px solid #DCDFE6;
  font-weight: 600;
}
/deep/.el-input.is-disabled .el-input__inner {
  color: #606266;
}
</style>
